package com.example.hnevc.androidui8;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
    EditText mEtUserNmae;
    EditText mEtPassword;
    Button mbtnRegist;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//获取控件保存到变量中
        mEtUserNmae=findViewById(R.id.et_username);
        mEtUserNmae=findViewById(R.id.et_password);
        mbtnRegist=findViewById(R.id.btn_regist);
        //设置控件事件
        mbtnRegist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //保存用户名和密码到内部文件dota.txt
                FileOutputStream fos= null;
                try {
                    fos = openFileOutput("data.txt",MODE_PRIVATE);
                    String data=mEtUserNmae.getText().toString()
                            +"-"
                            +mEtPassword.getText().toString();
                    fos.write(data.getBytes());
                    fos.close();

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }catch (IOException e){
                    e.printStackTrace();
                }

Intent intent = new Intent(MainActivity.thisActivity02.class);
         startActivity(intent);

            }
        });

    }
}
